﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Sale.Report
{
    public partial class 合同执行情况及一览 : System.Web.UI.Page
    {
        protected string year;
        protected string month;
        protected string RiQiStart;
        protected string RiQiEnd;
        protected string RiQi;


        /// <summary>
        /// 读入所有的SESSION数据，向VIEW暴露数据项
        /// </summary>
        protected void read_session()
        {
            year = DList_year.SelectedValue;
        }

        private string sql = @"
SELECT     
    dbo.产品订货单位.名称, 
    dbo.产品.品名, 
    SUM(dbo.产品销售合同.数量) AS 重量, 
    SUM(dbo.产品销售合同.金额) AS 金额
FROM  
    dbo.产品销售合同 INNER JOIN
    dbo.产品订货单位 ON dbo.产品销售合同.订货单位ID = dbo.产品订货单位.ID INNER JOIN
    dbo.产品 ON dbo.产品销售合同.产品ID = dbo.产品.ID
WHERE
    YEAR(dbo.产品销售合同.日期)=*年份*
GROUP BY dbo.产品订货单位.名称, dbo.产品.品名";
        protected static DateTime date;

        //SQL的初始化
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Message.Text = "·准备就绪";
            
            if (!this.IsPostBack)
            {
                DList_year.SelectedValue = DateTime.Now.Year.ToString();

                sql = sql.Replace("*年份*", DList_year.SelectedValue);

                this.SqlDataSource1.SelectCommand = sql;
                this.ViewState["SelectCommand"] = sql;
            }
            read_session();
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        //年份变化时
        protected void DList_year_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("*年份*", DList_year.SelectedValue);

            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }

        //月份变化时
        protected void DList_month_SelectedIndexChanged(object sender, EventArgs e)
        {
            sql = sql.Replace("*年份*", DList_year.SelectedValue);

            this.SqlDataSource1.SelectCommand = sql;
            this.ViewState["SelectCommand"] = sql;
            this.SqlDataSource1.SelectCommand = (string)this.ViewState["SelectCommand"];
        }
    }
}
